home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / SpinnerBeanInfo.java < prev    next >
Text File  |  1998-08-21  |  12KB  |  335 lines

  1. package symantec.itools.awt.util.spinner;
  2.  
  3. import java.beans.*;
  4. import symantec.itools.beans.*;
  5. import java.util.ResourceBundle;
  6.  
  7. //  10/06/97    LAB    Added semicolons to setEditable connections (Addresses Mac Bug #9004).
  8.  
  9. /**
  10.  * BeanInfo for Spinner.
  11.  *
  12.  */
  13.  
  14. public class SpinnerBeanInfo extends SimpleBeanInfo {
  15.  
  16.     /**
  17.      * Constructs a SpinnerBeanInfo object.
  18.      */
  19.     public SpinnerBeanInfo() {
  20.     }
  21.  
  22.     /**
  23.      * Gets a BeanInfo for the superclass of this bean.
  24.      * @return BeanInfo[] containing this bean's superclass BeanInfo
  25.      */
  26.     public BeanInfo[] getAdditionalBeanInfo() {
  27.         try {
  28.             BeanInfo[] bi = new BeanInfo[1];
  29.             bi[0] = Introspector.getBeanInfo(beanClass.getSuperclass());
  30.             return bi;
  31.         }
  32.         catch (IntrospectionException e) { throw new Error(e.toString());}
  33.     }
  34.  
  35.     /**
  36.      * Gets the SymantecBeanDescriptor for this bean.
  37.      * @return an object of type SymantecBeanDescriptor
  38.      * @see symantec.itools.beans.SymantecBeanDescriptor
  39.      */
  40.     public BeanDescriptor getBeanDescriptor() {
  41.         SymantecBeanDescriptor bd = new SymantecBeanDescriptor(beanClass);
  42.         bd.setCanAddChild(false);
  43.  
  44.         ResourceBundle conn = ResourceBundle.getBundle("symantec.itools.resources.ConnBundle");
  45.         bd.addConnectionDescriptor(new ConnectionDescriptor("output", "int", "",
  46.                                                 "%name%.ORIENTATION_VERTICAL",
  47.                                                 conn.getString("ORIENTATION_VERTICAL")));
  48.  
  49.         bd.addConnectionDescriptor(new ConnectionDescriptor("output", "int", "",
  50.                                                 "%name%.ORIENTATION_HORIZONTAL",
  51.                                                 conn.getString("ORIENTATION_HORIZONTAL")));
  52.  
  53.         return (BeanDescriptor) bd;
  54.     }
  55.  
  56.     /**
  57.      * Gets an array of descriptions of the methods used for "connections" by
  58.      * Visual CafΘ's Interaction Wizard.
  59.      * Included in each method description is a CONNECTIONS ConnectionDescriptor.
  60.      * @return method descriptions for this bean
  61.      * @see symantec.itools.beans.ConnectionDescriptor#CONNECTIONS
  62.      */
  63.     public MethodDescriptor[] getMethodDescriptors() {
  64.         Class[] args;
  65.         ConnectionDescriptor connection;
  66.         java.util.Vector connections;
  67.         java.util.Vector md = new java.util.Vector();
  68.         ResourceBundle conn = ResourceBundle.getBundle("symantec.itools.resources.ConnBundle");
  69.  
  70.         try{
  71.             args = null;
  72.             MethodDescriptor isEditable = new MethodDescriptor(beanClass.getMethod("isEditable", args));
  73.  
  74.             connections = new java.util.Vector();
  75.             connection = new ConnectionDescriptor("output", "boolean", "",
  76.                                     "%name%.isEditable()",
  77.                                     conn.getString("isEditable"));
  78.             connections.addElement(connection);
  79.  
  80.             connection = new ConnectionDescriptor("output", "boolean", "",
  81.                                     "!%name%.isEditable()",
  82.                                     conn.getString("isNonEditable"));
  83.             connections.addElement(connection);
  84.  
  85.             isEditable.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  86.             md.addElement(isEditable);
  87.         } catch (Exception e) { throw new Error("isEditable:: " + e.toString()); }
  88.  
  89.         try{
  90.             args = null;
  91.             MethodDescriptor getOrientation = new MethodDescriptor(beanClass.getMethod("getOrientation", args));
  92.  
  93.             connections = new java.util.Vector();
  94.             connection = new ConnectionDescriptor("output", "int", "",
  95.                                     "%name%.getOrientation()",
  96.                                     conn.getString("getOrientation"));
  97.             connections.addElement(connection);
  98.  
  99.             getOrientation.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  100.             md.addElement(getOrientation);
  101.         } catch (Exception e) { throw new Error("getOrientation:: " + e.toString()); }
  102.  
  103.         try{
  104.             args = new Class[1];
  105.             args[0] = java.lang.Boolean.TYPE ;
  106.             MethodDescriptor setWrappable = new MethodDescriptor(beanClass.getMethod("setWrappable", args));
  107.  
  108.             connections = new java.util.Vector();
  109.             connection = new ConnectionDescriptor("input", "boolean", "",
  110.                                     "%name%.setWrappable(%arg%);",
  111.                                     conn.getString("setWrappable"));
  112.             connections.addElement(connection);
  113.  
  114.             connection = new ConnectionDescriptor("input", "void", "",
  115.                                     "%name%.setWrappable(true);",
  116.                                     conn.getString("setWrappableTrue"));
  117.             connections.addElement(connection);
  118.  
  119.             connection = new ConnectionDescriptor("input", "void", "",
  120.                                     "%name%.setWrappable(false);",
  121.                                     conn.getString("setWrappableFalse"));
  122.             connections.addElement(connection);
  123.  
  124.             setWrappable.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  125.             md.addElement(setWrappable);
  126.         } catch (Exception e) { throw new Error("setWrappable:: " + e.toString()); }
  127.  
  128.         try{
  129.             args = null;
  130.             MethodDescriptor getMax = new MethodDescriptor(beanClass.getMethod("getMax", args));
  131.  
  132.             connections = new java.util.Vector();
  133.             connection = new ConnectionDescriptor("output", "int", "",
  134.                                     "%name%.getMax()",
  135.                                     conn.getString("getMax"));
  136.             connections.addElement(connection);
  137.  
  138.             getMax.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  139.             md.addElement(getMax);
  140.         } catch (Exception e) { throw new Error("getMax:: " + e.toString()); }
  141.  
  142.         try{
  143.             args = new Class[1];
  144.             args[0] = java.lang.Integer.TYPE ;
  145.             MethodDescriptor setMax = new MethodDescriptor(beanClass.getMethod("setMax", args));
  146.  
  147.             connections = new java.util.Vector();
  148.             connection = new ConnectionDescriptor("input", "int", "",
  149.                                     "%name%.setMax(%arg%);",
  150.                                     conn.getString("setMax"));
  151.             connections.addElement(connection);
  152.  
  153.             setMax.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  154.             md.addElement(setMax);
  155.         } catch (Exception e) { throw new Error("setMax:: " + e.toString()); }
  156.  
  157.         try{
  158.             args = new Class[1];
  159.             args[0] = java.lang.Integer.TYPE ;
  160.             MethodDescriptor setOrientation = new MethodDescriptor(beanClass.getMethod("setOrientation", args));
  161.  
  162.             connections = new java.util.Vector();
  163.             connection = new ConnectionDescriptor("input", "int", "",
  164.                                     "%name%.setOrientation(%arg%);",
  165.                                     conn.getString("setOrientation"));
  166.             connections.addElement(connection);
  167.  
  168.             setOrientation.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  169.             md.addElement(setOrientation);
  170.         } catch (Exception e) { throw new Error("setOrientation:: " + e.toString()); }
  171.  
  172.         try{
  173.             args = new Class[1];
  174.             args[0] = java.lang.Integer.TYPE ;
  175.             MethodDescriptor setCurrent = new MethodDescriptor(beanClass.getMethod("setCurrent", args));
  176.  
  177.             connections = new java.util.Vector();
  178.             connection = new ConnectionDescriptor("input", "int", "",
  179.                                     "%name%.setCurrent(%arg%);",
  180.                                     conn.getString("setCurrent"));
  181.             connections.addElement(connection);
  182.  
  183.             setCurrent.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  184.             md.addElement(setCurrent);
  185.         } catch (Exception e) { throw new Error("setCurrent:: " + e.toString()); }
  186.  
  187.         try{
  188.             args = null;
  189.             MethodDescriptor getMin = new MethodDescriptor(beanClass.getMethod("getMin", args));
  190.  
  191.             connections = new java.util.Vector();
  192.             connection = new ConnectionDescriptor("output", "int", "",
  193.                                     "%name%.getMin()",
  194.                                     conn.getString("getMin"));
  195.             connections.addElement(connection);
  196.  
  197.             getMin.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  198.             md.addElement(getMin);
  199.         } catch (Exception e) { throw new Error("getMin:: " + e.toString()); }
  200.  
  201.         try{
  202.             args = new Class[1];
  203.             args[0] = java.lang.Integer.TYPE ;
  204.             MethodDescriptor setMin = new MethodDescriptor(beanClass.getMethod("setMin", args));
  205.  
  206.             connections = new java.util.Vector();
  207.             connection = new ConnectionDescriptor("input", "int", "",
  208.                                     "%name%.setMin(%arg%);",
  209.                                     conn.getString("setMin"));
  210.             connections.addElement(connection);
  211.  
  212.             setMin.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  213.             md.addElement(setMin);
  214.         } catch (Exception e) { throw new Error("setMin:: " + e.toString()); }
  215.  
  216.         try{
  217.             args = new Class[1];
  218.             args[0] = java.lang.Boolean.TYPE ;
  219.             MethodDescriptor setEditable = new MethodDescriptor(beanClass.getMethod("setEditable", args));
  220.  
  221.             connections = new java.util.Vector();
  222.             connection = new ConnectionDescriptor("input", "boolean", "",
  223.                                     "%name%.setEditable(%arg%);",
  224.                                     conn.getString("setEditable"));
  225.             connections.addElement(connection);
  226.  
  227.             connection = new ConnectionDescriptor("input", "void", "",
  228.                                     "%name%.setEditable(true);",
  229.                                     conn.getString("setEditableTrue"));
  230.             connections.addElement(connection);
  231.  
  232.             connection = new ConnectionDescriptor("input", "void", "",
  233.                                     "%name%.setEditable(false);",
  234.                                     conn.getString("setEditableFalse"));
  235.             connections.addElement(connection);
  236.  
  237.             setEditable.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  238.             md.addElement(setEditable);
  239.         } catch (Exception e) { throw new Error("setEditable:: " + e.toString()); }
  240.  
  241.         try{
  242.             args = null;
  243.             MethodDescriptor isWrappable = new MethodDescriptor(beanClass.getMethod("isWrappable", args));
  244.  
  245.             connections = new java.util.Vector();
  246.             connection = new ConnectionDescriptor("output", "boolean", "",
  247.                                     "%name%.isWrappable()",
  248.                                     conn.getString("isWrappable"));
  249.             connections.addElement(connection);
  250.  
  251.             connection = new ConnectionDescriptor("output", "boolean", "",
  252.                                     "!%name%.isWrappable()",
  253.                                     conn.getString("isNotWrappable"));
  254.             connections.addElement(connection);
  255.  
  256.             isWrappable.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  257.             md.addElement(isWrappable);
  258.         } catch (Exception e) { throw new Error("isWrappable:: " + e.toString()); }
  259.  
  260.         try{
  261.             args = null;
  262.             MethodDescriptor getCurrent = new MethodDescriptor(beanClass.getMethod("getCurrent", args));
  263.  
  264.             connections = new java.util.Vector();
  265.             connection = new ConnectionDescriptor("output", "int", "",
  266.                                     "%name%.getCurrent()",
  267.                                     conn.getString("getCurrent"));
  268.             connections.addElement(connection);
  269.  
  270.             getCurrent.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  271.             md.addElement(getCurrent);
  272.         } catch (Exception e) { throw new Error("getCurrent:: " + e.toString()); }
  273.  
  274.         MethodDescriptor[] rv = new MethodDescriptor[md.size()];
  275.         md.copyInto(rv);
  276.  
  277.         return rv;
  278.     }
  279.  
  280.     /**
  281.      * Returns descriptions of this bean's properties.
  282.      */
  283.     public PropertyDescriptor[] getPropertyDescriptors() {
  284.         ResourceBundle prop = ResourceBundle.getBundle("symantec.itools.resources.PropBundle");
  285.  
  286.         try{
  287.         PropertyDescriptor orientation = new PropertyDescriptor("orientation", beanClass);
  288.         orientation.setBound(true);
  289.         orientation.setConstrained(true);
  290.         orientation.setDisplayName(prop.getString("orientation"));
  291.         orientation.setValue("ENUMERATION", "ORIENTATION_VERTICAL=0, ORIENTATION_HORIZONTAL=1");
  292.  
  293.         PropertyDescriptor min = new PropertyDescriptor("min", beanClass);
  294.         min.setBound(true);
  295.         min.setConstrained(true);
  296.         min.setDisplayName(prop.getString("minimum"));
  297.  
  298.         PropertyDescriptor max = new PropertyDescriptor("max", beanClass);
  299.         max.setBound(true);
  300.         max.setConstrained(true);
  301.         max.setDisplayName(prop.getString("maximum"));
  302.  
  303.         PropertyDescriptor current = new PropertyDescriptor("current", beanClass);
  304.         current.setBound(true);
  305.         current.setConstrained(true);
  306.         current.setDisplayName(prop.getString("value"));
  307.  
  308.         PropertyDescriptor editable = new PropertyDescriptor("editable", beanClass);
  309.         editable.setBound(true);
  310.         editable.setConstrained(true);
  311.         editable.setDisplayName(prop.getString("editable"));
  312.  
  313.         PropertyDescriptor wrappable = new PropertyDescriptor("wrappable", beanClass);
  314.         wrappable.setBound(true);
  315.         wrappable.setConstrained(true);
  316.         wrappable.setDisplayName(prop.getString("wrappable"));
  317.  
  318.         PropertyDescriptor layout = new PropertyDescriptor("layout", beanClass);
  319.         layout.setHidden(true);
  320.  
  321.         PropertyDescriptor[] rv = {
  322.             orientation,
  323.             min,
  324.             max,
  325.             current,
  326.             editable,
  327.             wrappable,
  328.             layout};
  329.         return rv;
  330.         } catch (IntrospectionException e) { throw new Error(e.toString()); }
  331.     }
  332.  
  333.     private final static Class beanClass = Spinner.class;
  334.  
  335.     }    //  end of class SpinnerBeanInfo